<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$cashierid=$this->checklogin();
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'cashierid'=>$cashierid);
    $fields='';
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_cashier_qrcode',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
		$v['url']=custom_url('jy_cashier/pay//qrid='.$v['id'],true);
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'二维码管理'),
			array('op'=>'edit','title'=>'添加二维码'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'二维码名称','type'=>'string'),
			array('name'=>'goodstitle','title'=>'收款名称','type'=>'string'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		)),
	);	
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_cashier_qrcode',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'二维码设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'二维码管理'),
			array('op'=>'edit','title'=>'添加二维码')
		),
		'edit'=>array(
			array('name'=>'title','title'=>'二维码名称','type'=>'string'),
			array('name'=>'goodstitle','title'=>'收款名称','type'=>'string'),
			array('name'=>'money','title'=>'固定金额','type'=>'string','help'=>'不填金额，则表示金额由客户输入！'),
			)
	);
	
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写二维码名称！','error');
	}
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_cashier_qrcode',$postdata,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $postdata['uniacid']=$_SESSION['uniacid'];
				$postdata['cashierid']=$cashierid;
				$postdata['createtime']=time();
				pdo_insert('jy_cashier_qrcode',$postdata);
				exi('添加成功！','','list');
			}
	}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_cashier_qrcode',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_cashier_qrcode',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>